﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Velocity4Net.Ctx;

namespace Velocity4Net.App.Events
{
    class ShouldLogOnNullSetExecutor : EventHandlerMethodExecutor
    {
        private IContext context;
        private String lhs;
        private String rhs;

        /**
         * when this is false, quit iterating
         */
        private bool result = true;
        private bool executed = false;

        public ShouldLogOnNullSetExecutor(
                IContext context, 
                String lhs, 
                String rhs) 
        {
            this.context = context;
            this.lhs = lhs;
            this.rhs = rhs;
        }

        /**
         * Call the method shouldLogOnNullSet()
         *  
         * @param handler call the appropriate method on this handler
         */
        public void execute(EventHandler handler)
        {
            NullSetEventHandler eh = (NullSetEventHandler) handler;
            
            //if (eh is ContextAware)
            //    ((ContextAware) eh).setContext(context);

            executed = true;
            result = ((NullSetEventHandler) handler).shouldLogOnNullSet(lhs, rhs); 
        }

        public Object getReturnValue()
        {            
            // return new Boolean(result);
            return result;
        }

        public bool isDone()
        {
            return executed && !result;
        }        
        
        
    }
}
